//! 日志测试示例
//! 
//! 测试环境日志打印功能

use binance_sdk_unified::{
    client::BinanceClientBuilder, ProductType, Environment, Result,
};

#[tokio::main]
async fn main() -> Result<()> {
    // 初始化日志
    tracing_subscriber::fmt::init();

    println!("🔍 环境日志测试");
    println!("================");

    // 测试不同环境的环境日志
    let test_cases = vec![
        ("现货-Demo模式", ProductType::Spot, Environment::Demo),
        ("USDT合约-Demo模式", ProductType::UsdM, Environment::Demo),
        ("币本位合约-Demo模式", ProductType::CoinM, Environment::Demo),
        ("现货-生产网", ProductType::Spot, Environment::Live),
        ("USDT合约-生产网", ProductType::UsdM, Environment::Live),
    ];

    for (name, product_type, environment) in test_cases {
        println!("\n📋 测试: {}", name);
        
        // 创建客户端
        let client = BinanceClientBuilder::new(
            "test_api_key".to_string(),
            "test_secret_key".to_string(),
            product_type,
        )
        .environment(environment)
        .build()?;

        // 打印配置信息
        println!("   产品类型: {:?}", product_type);
        println!("   环境: {:?}", environment);
        println!("   REST URL: {}", client.config().rest_base_url());
        println!("   WebSocket URL: {}", client.config().ws_base_url());
        
        // 添加环境日志
        tracing::info!("[LOG_TEST] 测试: {}", name);
        tracing::info!("[LOG_TEST] 产品类型: {:?}", product_type);
        tracing::info!("[LOG_TEST] 环境: {:?}", environment);
        tracing::info!("[LOG_TEST] REST URL: {}", client.config().rest_base_url());
        tracing::info!("[LOG_TEST] WebSocket URL: {}", client.config().ws_base_url());
        
        // 测试API连接
        match client.rest().market().get_server_time().await {
            Ok(server_time) => {
                println!("   ✅ 服务器时间: {}", server_time.server_time);
                tracing::info!("[LOG_TEST] API连接成功 - 服务器时间: {}", server_time.server_time);
            },
            Err(e) => {
                println!("   ❌ 连接失败: {}", e);
                tracing::error!("[LOG_TEST] API连接失败: {}", e);
            }
        }
    }

    println!("\n✅ 环境日志测试完成！");
    println!("查看上面的日志输出，确认环境信息正确打印");
    
    tracing::info!("[LOG_TEST] 所有测试完成");

    Ok(())
}
